package cn.com.cifi.mars.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.com.cifi.mars.constant.IsDeleteEnum;
import cn.com.cifi.mars.entity.BudgetVersionIdentify;
import cn.com.cifi.mars.mapper.mars.BudgetVersionIdentifyMapper;
import cn.com.cifi.mars.service.BudgetVersionIdentifyService;
import cn.com.cifi.mars.util.StrUtils;

/**
 * <p>
 * 预算版本标识表 服务实现类
 * </p>
 *
 * @author yyd
 * @since 2021-05-10
 */
@Service
public class BudgetVersionIdentifyServiceImpl extends ServiceImpl<BudgetVersionIdentifyMapper, BudgetVersionIdentify> implements BudgetVersionIdentifyService {

	@Autowired
	BudgetVersionIdentifyMapper budgetVersionIdentifyMapper;

	@Override
	public void updateVersionIdentify(String isBudget, String versionCode, String version) {
		//1、清除历史数据
		budgetVersionIdentifyMapper.removeVersion(IsDeleteEnum.YES.getKey());
		//2、新增最新版本
		budgetVersionIdentifyMapper.insertVersion(isBudget,versionCode,version,IsDeleteEnum.NO.getKey());
	}

	@Override
	public String getVersion() {
		BudgetVersionIdentify obj = budgetVersionIdentifyMapper.selectVersion(IsDeleteEnum.NO.getKey());
		if(obj != null && StrUtils.isNotEmpty(obj.getIsBudget()) && obj.getIsBudget().equals("是")) {
			return obj.getVersionIdentify();
		}
		return "";
	}
}
